import urlConfig from './config.js'

const request = {}
const headers = {}

request.globalRequest = (url, method, data, power) => {

	//从缓存取token
	headers['token'] = uni.getStorageSync('token')
	console.log('headers["token"]:'+uni.getStorageSync('token'))
    return uni.request({
        url: urlConfig + url,
        method,
        data: data,
        dataType: 'json',
        header: headers
    })
        .then(res => {
            if (res[1].data.status) {
                return res[1]
            } else {
				if(res[1].data.msg!=null){
					uni.showToast({
					    title: res[1].data.msg,
					    icon: 'none'
					})
				}
				throw res[1].data      
            }
        })
        .catch(params => {
            uni.showToast({
                title: params.msg,
                icon: 'none'
            })
            return Promise.reject(params)
        })
}
export default request